#!/usr/bin/env python
# -*-coding:utf-8-*-
# File    : liyuqi.py
# Date    : 2021-02-20
# Author  : Tom.Lee


from datetime import datetime
import os

now = datetime.now()

startdate = datetime.strptime('2021-01-18', '%Y-%m-%d')

interal = (now - startdate).days + 1
print("今天是打卡的第{}天".format(interal))

dirname = os.path.join(os.getcwd(), "Day{:0>2}".format(interal))
if os.path.exists(dirname):
    print("{} 已存在".format(dirname))
else:
    os.makedirs(dirname, exist_ok=True)
    print("{} 创建成功".format(dirname))

pyfile = os.path.join(dirname, "liyuqi.py")
py_content = '''#!/usr/bin/env python
# -*-coding:utf-8-*-
# File    : liyuqi.py'''
if os.path.isfile(pyfile):
    print("{} 已存在".format(pyfile))
else:
    fs = open(pyfile, 'w')
    fs.write(py_content)
    fs.close()
    print("{} 创建成功".format(pyfile))

mdfile = os.path.join(dirname, "README.md")
md_conten = '#########第{}道题'.format(interal).encode("utf-8")
if os.path.isfile(mdfile):
    print("{} 已存在".format(mdfile))
else:
    fs = open(mdfile, 'wb')
    fs.write(md_conten)
    fs.close()
    print("{} 创建成功".format(mdfile))
